package com.ruoyi.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.admin.domain.entity.ProfitModel;
import com.ruoyi.admin.domain.vo.request.profit.ProfitPageJoinRequest;
import com.ruoyi.admin.domain.vo.response.profit.ProfitPageJoinResponse;
import com.ruoyi.admin.domain.vo.response.profit.ProfitPageResponse;
import com.ruoyi.admin.domain.vo.response.profit.ProfitResponse;
import com.ruoyi.admin.domain.vo.response.scheduling.SchedulingPageJoinResponse;
import com.ruoyi.admin.domain.vo.response.scheduling.SchedulingPageResponse;
import com.ruoyi.admin.mapper.ProfitMapper;
import com.ruoyi.admin.service.ProfitService;
import com.ruoyi.common.api.Result;
import com.ruoyi.common.api.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 报表(Profit)Service实现类
 *
 * @author jianhan
 * @date 2022-12-07 15:41:39
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ProfitServiceImpl extends ServiceImpl<ProfitMapper, ProfitModel> implements ProfitService {

    private static final Logger logger = LoggerFactory.getLogger(ProfitServiceImpl.class);

    @Override
    public Result<ProfitResponse> getId(Long profitId) {
        ProfitModel profitModel = this.getById(profitId);
        if (profitModel != null) {
            ProfitResponse profitResponse = new ProfitResponse(profitModel);
            return Result.success(profitResponse);
        }
        return Result.failed(ResultCode.DATA_NOT_EXIST);
    }

    @Override
    public Result<ProfitPageResponse> page(Page<ProfitPageJoinRequest> page, ProfitPageJoinRequest profitPageJoinRequest) {
        Page<ProfitPageJoinResponse> pages = baseMapper.queryPage(page, profitPageJoinRequest);
        ProfitPageResponse profitPageResponse = new ProfitPageResponse(pages);
        return Result.success(profitPageResponse);
    }

    @Override
    public Result add(ProfitModel profitModel) {
        Boolean result = this.save(profitModel);
        if (result) {
            return Result.success();
        }
        return Result.failed("添加失败");
    }

    @Override
    public Result update(ProfitModel profitModel) {
        Boolean result = this.updateById(profitModel);
        if (result) {
            return Result.success();
        }
        return Result.failed("更新失败");
    }

    @Override
    public Result delete(Long profitId) {
        Boolean result = this.removeById(profitId);
        return Result.judge(result);

    }

    private QueryWrapper<ProfitModel> queryWrapper(ProfitModel profitModel) {
        QueryWrapper<ProfitModel> queryWrapper = new QueryWrapper<>();
        
        /*
           写搜索条件
        */
        queryWrapper.orderByDesc("id");
        return queryWrapper;
    }

}
